home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Idle
/
Periodic.cp
< prev
next >
Wrap
Text File
|
1997-06-28
|
1KB
|
80 lines
// Periodic.cp
#ifndef Periodic_h
#include "Periodic.h"
#endif
Periodic::Periodic( const Method& method,
uint32 thePeriod,
bool startEnabled )
: Enableable( startEnabled ),
repeat( this, &Periodic::Repeat ),
inProgress( false ),
toRepeat( method ),
period( thePeriod ),
nextTime( 0 )
{
Assert( period < maxuint32 / 4 );
if ( startEnabled )
{
nextTime = Tick::Now() + period;
repeat.DelayTo( nextTime );
}
}
void Periodic::BeEnabled()
{
nextTime = Tick::Now() + period;
if ( !inProgress )
repeat.DelayTo( nextTime );
}
void Periodic::BeDisabled()
{
if ( !inProgress )
repeat.Cancel();
}
void Periodic::Repeat()
{
Assert( !inProgress );
Assert( Enabled() );
nextTime += period;
inProgress = true;
toRepeat();
inProgress = false;
if ( Enabled() )
{
Tick now( Tick::Now() );
if ( nextTime < now )
nextTime = now + period;
repeat.DelayTo( nextTime );
}
}
void Periodic::Synchronize()
{
Assert( Enabled() );
nextTime = Tick::Now() + period;
if ( !inProgress )
{
repeat.Cancel();
repeat.DelayTo( nextTime );
}
}
void Periodic::SetPeriod( uint32 p )
{
Assert( p < maxuint32 / 4 );
period = p;
Synchronize();
}